//
//  LHBaseTableViewController.swift
//  sinaWeibo
//
//  Created by LiHong on 15/10/26.
//  Copyright © 2015年 LiHong. All rights reserved.
//

import UIKit

class LHBaseTableViewController: UITableViewController {

    let userLogin = LHUserAccount.userLogin()
    override func loadView() {
        userLogin ? super.loadView() : setupVistorView()
    }

    
    func setupVistorView() {
        let visterView = LHVistorView()
        view = visterView
 //       view.backgroundColor = UIColor.whiteColor()
       // view.backgroundColor = UIColor(red: 232, green: 233, blue: 232, alpha: 0)
        if self is LHHomeTableViewController{
            visterView.startRotationAnimation()
            // 监听程序推到后台
            NSNotificationCenter.defaultCenter().addObserver(self, selector: "didEnterBackground", name: UIApplicationDidEnterBackgroundNotification, object: nil)
            NSNotificationCenter.defaultCenter().addObserver(self, selector: "didBecomeActive", name: UIApplicationDidBecomeActiveNotification, object: nil)
            
            
        }else if self is LHMessageTableViewController{
            visterView.setupInfo("visitordiscover_image_message", messagge: "登陆后，别人评论你的微博，发给你的消息，都会在这里收到通知")
        }else if self is LHDiscoverTableViewController{
            visterView.setupInfo("visitordiscover_image_message", messagge: "登陆后，最新、最热微博尽在掌握，不再会与实事潮流擦肩而过")
        }else if self is LHProfileTableViewController{
            visterView.setupInfo("visitordiscover_image_profile", messagge: "登陆后，你的微博、相册、个人资料会显示在这里，展示给别人")
        }
        visterView.vistorViewDelegate = self
        
        navigationItem.leftBarButtonItem = UIBarButtonItem(title: "注册", style: UIBarButtonItemStyle.Plain, target: self, action: "vistorViewWillRegister")
        navigationItem.rightBarButtonItem = UIBarButtonItem(title: "登录", style: UIBarButtonItemStyle.Plain, target: self, action: "vistorViewWillLogin")
    }
    
    func didEnterBackground() {
        (view as! LHVistorView).pauseAnimation()
    }
    func didBecomeActive() {
        (view as! LHVistorView).resumeAnimation()
    }
}
// 扩展 category
extension LHBaseTableViewController: LHVistorViewDelegate{
    //MARK: - 代理方法
    func vistorViewWillRegister(){
        print("vistorViewWillRegister \(__FUNCTION__)")
    }
    func vistorViewWillLogin(){
    //    print("vistorViewWillLogin \(__FUNCTION__)")
        
        presentViewController(UINavigationController(rootViewController: LHOAuthViewController()), animated: true, completion: nil)
    }
}
